package com.xiaomili.halfsugar.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.xiaomili.halfsugar.R;

import java.io.File;
import java.util.List;

/**
 * Created by Administrator on 2016/7/20 0020.
 */
public class ChildAdapter extends RecyclerView.Adapter<ChildAdapter.ChildHolder> {

    private Context mContext;
    private List<String> mDatas;

    public ChildAdapter(Context mContext, List<String> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
    }

    @Override
    public ChildHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_child, parent, false);
        return new ChildHolder(view);
    }

    @Override
    public void onBindViewHolder(ChildHolder holder, int position) {
        Picasso.with(mContext).load(new File(mDatas.get(position)))
                .centerInside()
                .config(Bitmap.Config.RGB_565)
                .resize(200,200)
                .into(holder.iv_child);
    }

    @Override
    public int getItemCount() {
        return mDatas==null?0:mDatas.size();
    }

    class ChildHolder extends RecyclerView.ViewHolder{

        private ImageView iv_child;
        public ChildHolder(View itemView) {
            super(itemView);
            iv_child = (ImageView) itemView.findViewById(R.id.iv_child);
        }
    }
}
